#!/usr/bin/env python3
#-*- coding:utf-8 -*-

import matplotlib.pyplot as plt
import numpy as np
import random

def mean(data):
    mean = sum(data) / 9
    return mean


# 数据
test_cases = ['403.gcc', '445.gobmk', '450.soplex', '473.astar', '605.mcf', '619.lbm', '621.wrf', '627.cam4', '654.roms', 'AVG']
bingo = [random.randint(43, 67) for _ in range(9)] # 规则模式
spp = [random.randint(43, 67) for _ in range(9)] # 复杂模式
mlop = [random.randint(43, 67) for _ in range(9)] # 机器学习
pythia = [random.randint(43, 67) for _ in range(9)] # 强化学习
crlp = [random.randint(43, 68) for _ in range(9)] # 本文

avg_bingo = mean(bingo)
avg_spp = mean(spp)
avg_mlop = mean(mlop)
avg_pythia = mean(pythia)
avg_crlp = mean(crlp)

bingo += [avg_bingo]
spp += [avg_spp]
mlop += [avg_mlop]
pythia += [avg_pythia]
crlp += [avg_crlp]

print("Bingo:", round((avg_crlp-avg_bingo)*100/avg_bingo, 1), "%")
print("SPP:", round((avg_crlp-avg_spp)*100/avg_spp, 1), "%")
print("MLOP", round((avg_crlp-avg_mlop)*100/avg_mlop, 1), "%")
print("PYTHIA", round((avg_crlp-avg_pythia)*100/avg_pythia, 1), "%")

x = np.arange(len(test_cases))  # X轴位置
width = 0.15  # 柱子宽度

# 绘制柱状图
plt.bar(x - 1.5*width, bingo, width, label='Bingo', color='blue')
plt.bar(x - 0.5*width, spp, width, label='SPP', color='brown')
plt.bar(x + 0.5*width, mlop, width, label='MLOP', color='orange')
plt.bar(x + 1.5*width, pythia, width, label='Pythia', color='green')
plt.bar(x + 2.5*width, crlp, width, label='CRLP', color='red')

title = 'Accuracy'

# 添加标签和标题
plt.xlabel('Test Cases')
plt.ylabel(title + ' (%)')
plt.title(title + ' by Test Case')
plt.xticks(x, test_cases, rotation=45)
plt.legend()

# 显示图表
plt.tight_layout()
plt.show()
